<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useDevice } from '@/hooks/device'
import { useRouter } from 'vue-router'
import PcViewNav from '@/layout/PC/components/PCViewNav.vue'
import MtViewNav from '@/layout/Mobile/components/MTViewNav.vue'
import operation from '@/layout/Mobile/components/Operation.vue'

const router = useRouter()
const dynamicWidth = computed(() => {
  if (useDevice.value === 'pc') {
    return `calc(100vw - 480px)`
  } else {
    return `calc(100vw - 40px)`
  }
})
const pcDevice = computed(() => {
  return useDevice.value === 'pc'
})
const padding = computed(() => {
  if (useDevice.value === 'pc') {
    return '20px'
  } else {
    return '20px 20px 0'
  }
})
const isPc = computed(() => {
  if (useDevice.value === 'pc') {
    return true
  } else {
    return false
  }
})
onMounted(() => {
  if (useDevice.value === 'mobile') {
    router.replace('/homeView/user')
  }
})
</script>

<template>
  <operation v-if="!pcDevice" />
  <div class="container">
    <pc-view-nav v-if="pcDevice" />
    <div class="template-box" :class="isPc ? 'pc-gap' : 'mt-gap'">
      <router-view v-slot="{ Component }">
        <transition name="slide-fade">
          <component :is="Component" />
        </transition>
      </router-view>
    </div>
    <mt-view-nav v-if="!pcDevice" />
  </div>
</template>

<style scoped lang="scss">
@import '@/scss/functions';
.slide-fade-enter-active {
  transition: all 0.3s ease-out;
}

.slide-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateX(20px);
  opacity: 0;
}

.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: v-bind(padding);

  .template-box {
    @include scrollbar(0px);
    flex: 1;
    border-radius: 8px;
    box-shadow: 0 0 8px 0 var(--shadow-color);
    width: v-bind(dynamicWidth);
    margin: 20px auto 0;
    padding: 0 20px;
    height: 100dvh;
    overflow-y: auto;

    &.pc-gap {
      --gap: 20px;
      position: relative;
      &::before {
        content: '';
        display: inline-block;
        width: calc(100% + 20px);
        height: var(--gap);
        position: sticky;
        top: 0;
        left: 0;
        margin-left: -10px;
        z-index: 2;
        background: var(--body-bg-color);
      }
      &::after {
        content: '';
        display: inline-block;
        width: calc(100% + 20px);
        height: var(--gap);
        position: sticky;
        bottom: 0;
        margin-left: -10px;
        z-index: 2;
        background: var(--body-bg-color);
      }
    }

    &.mt-gap {
      padding: 20px;
    }
  }

  @keyframes test {
    0% {
      transform: skew(359deg, -359deg) translate3d(0, 0, 0);
    }
    100% {
      transform: skew(290deg, -340deg) translate3d(100%, 150%, 0);
    }
  }
}
</style>
